import { useDispatch, useSelector, useStore } from 'react-redux';

export const useAppDispatch = () => useDispatch();
export const useAppSelector = useSelector;
export const useAppStore = () => useStore();

// 权限检查Hook
export const usePermission = () => {
  const permissions = useAppSelector(state => state.user.permissions);
  
  // 检查是否拥有某个权限
  const hasPermission = (permission) => {
    if (!permissions) return false;
    return permissions.includes(permission);
  };
  
  // 检查是否拥有多个权限中的任意一个
  const hasAnyPermission = (permissionList) => {
    if (!permissions || !Array.isArray(permissionList)) return false;
    return permissionList.some(permission => permissions.includes(permission));
  };
  
  // 检查是否拥有所有指定权限
  const hasAllPermissions = (permissionList) => {
    if (!permissions || !Array.isArray(permissionList)) return false;
    return permissionList.every(permission => permissions.includes(permission));
  };
  
  return {
    permissions,
    hasPermission,
    hasAnyPermission,
    hasAllPermissions
  };
};
